package com.food.controller;

import com.food.entity.dto.FoodReviewDto;
import com.food.entity.vo.FoodReviewVO;
import com.food.service.FoodReviewService;
import com.food.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reviews")
public class FoodReviewController {

    @Autowired
    private FoodReviewService foodReviewService;

    // 添加评价
    @PostMapping
    public R<Void> addReview(@RequestBody FoodReviewDto dto) {
        foodReviewService.addReview(dto);
        return R.success(null);
    }

    // 获取某美食所有评价
    @GetMapping("/{foodId}")
    public R<List<FoodReviewVO>> getReviews(@PathVariable Integer foodId) {
        List<FoodReviewVO> reviews = foodReviewService.getReviewsByFoodId(foodId);
        return R.success(reviews);
    }

    // 删除评价
    @DeleteMapping("/{reviewId}")
    public R<Void> deleteReview(@PathVariable Integer reviewId) {
        foodReviewService.deleteReviewById(reviewId);
        return R.success(null);
    }
}
